<!--测试包新增-->
<template>
  <div>
    <dialog-edit :visible.sync="dialogVisible" :title="$attrs.Title||'新增测试包'" ref="userManageEdit" width="600"
                 height="350" @save="save" :saveLoading="saveLoading">
      <template slot="body">
        <el-form class="formBox" style="padding: 10px;"
                 ref="formref"
                 title-width="120"
                 label-position="top"
                 :model="form"
                 :rules="formRules">
          <el-form-item label="名称" prop="Name">
            <el-input v-model="form.Name" :maxlength="50"></el-input>
          </el-form-item>
          <el-form-item label="备注" prop="Remarks">
            <el-input v-model="form.Remarks" :maxlength="255"></el-input>
          </el-form-item>
        </el-form>
      </template>
    </dialog-edit>
  </div>
</template>

<script>
import testCasePackApi from "@/api/testCasePackApi";
import dialogEdit from '@/components/element/dialogEdit'
export default {
  name: "testPackAdd",
  components: {
    dialogEdit
  },
  props: {
    visible: Boolean,
    form: Object
  },
  computed: {
    dialogVisible: {
      get () {
        return this.visible
      },
      set (val) {
        this.$emit('update:visible', val)
      }
    }
  },
  data () {
    return {
      saveLoading: false,
      formRules: {
        Name: [{ required: true, message: '请填写测试包名称', trigger: 'change' }]
      }
    }
  },
  methods: {
    save () {
      console.log(this.form)
      this.$refs.formref.validate((valid) => {
        if (valid) {
          this.saveLoading = true
          testCasePackApi.createCase(this.form).then(res => {
            this.$message({type: res.code === 1 ? 'success' : 'warning', message: res.message})
            this.dialogVisible = false
            this.$emit('suClose')
          }).finally(() => {
            this.saveLoading = false
          })
        } else {
          this.$message({type: 'warning', message: '请检查标红位置'})
        }
      })
    }
  },
  watch: {
    dialogVisible (n, o) {
      this.$nextTick(() => {
        this.$refs.formref.clearValidate()
      })
    }
  }
}
</script>

<style scoped>

</style>